package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.innovation.chengzhangriji.R;

public class BabySideView extends View {

    private static final int DISTANCE = 32;

    private int mDistance;

    private int mCount;

    private Paint mPaint;

    private Bitmap mBitmap;

    public BabySideView(Context context) {
        super(context);
        init();
    }

    public BabySideView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public BabySideView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int height = getHeight();
        float density = getResources().getDisplayMetrics().density;
        mDistance = (int) (density * DISTANCE);
        mCount = (height - mDistance * 2) / mDistance;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        for (int i = 0; i < mCount; i++) {
            canvas.drawBitmap(mBitmap, 0, (i + 1) * mDistance, mPaint);
        }
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_side);
    }
}
